//
//  MeInterestTbv.m
//  ZITHER
//
//  Created by weixin on 2018/10/16.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MeInterestTbv.h"
#import "MeInterestCell.h"
#import "MyselfFollowListModel.h"
#import "Ugc_HomePage_VC_V3.h"

@interface MeInterestTbv ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)MyselfFollowListModel * model;

@end

@implementation MeInterestTbv

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self defaultConfiguration];
    }
    return self;
}
- (void)Starefreshing{
    [self loadData];
}

-(void)setType:(NSInteger)type{
    _type = type;
    [self loadData];
}

-(void)loadData{
    
    if (self.type == 1) {
        //    /** 关注我的列表 */
        [[serviceDefualt loadGetFollowMeListPage:self.page reponseObjctClass:[MyselfFollowListModel class]]subscribeNext:^(ResponseData * x) {
            if (x.success) {
                MyselfFollowListModel * model = x.responseData;
                [self setNoMoreDataBg:YES NoDataState:NoMoreDataStateDefault];
                if (model.list.count == 0 ) {
                    if (self.page == 0) {
                        [self setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
                        self.noMoreDateView.title.text = @"还没有人关注你";
                        [Tools showTips:@"暂无更多数据"];
                        [self endRefreshing];
                        self.model.list = [[NSMutableArray alloc]init];
                        [self endRefreshing];
                        [self reloadData];
                        [self.mj_footer endRefreshingWithNoMoreData];
                    }else{
                        [self.mj_footer endRefreshingWithNoMoreData];
                    }
                    return ;
                }
                if (self.page == 0) {
                    [self.mj_footer resetNoMoreData];
                    self.model = x.responseData;
                }else{
                    for (MyselfFollowListModelSub * modelSub in x.responseData) {
                        [self.model.list addObject:modelSub];
                    }
                }
            }else{
                if (![x.errorInfo isEqualToString:@"未登录"]) {
                     [Tools showTips:x.errorInfo];
                }
            }
            [self endRefreshing];
            [self reloadData];
        }];
    }else{

        
        /** 我的关注列表 */
        [[serviceDefualt loadGetMyselfFollowListPage:self.page reponseObjctClass:[MyselfFollowListModel class]]subscribeNext:^(ResponseData * x) {
            if (x.success) {
                [self setNoMoreDataBg:YES NoDataState:NoMoreDataStateDefault];
                MyselfFollowListModel * model = x.responseData;
                if (model.list.count == 0) {
                    if (self.page == 0) {
                        [self setNoMoreDataBg:NO NoDataState:NoMoreDataStateDefault];
                        self.noMoreDateView.title.text = @"没有关注别人";
                        [Tools showTips:@"暂无更多数据"];
                        [self endRefreshing];
                        self.model.list = [[NSMutableArray alloc]init];
                        [self endRefreshing];
                        [self reloadData];
                        [self.mj_footer endRefreshingWithNoMoreData];

                    }else{
                        [self.mj_footer endRefreshingWithNoMoreData];
                    }
                    return ;
                }
                if (self.page == 0) {
                    [self.mj_footer resetNoMoreData];
                    self.model = x.responseData;
                }else{
                    MyselfFollowListModel *model = x.responseData;
                    for (MyselfFollowListModelSub * modelSub in model.list) {
                        [self.model.list addObject:modelSub];
                    }
                }
            }else{
                if (![x.errorInfo isEqualToString:@"未登录"]) {
                     [Tools showTips:x.errorInfo];
                }
            }
            [self endRefreshing];
            [self reloadData];
        }];
    }

}

-(void)defaultConfiguration{
    self.delegate = self;
    self.dataSource = self;

}

#pragma mark -- tabdelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.model.list.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *sectionCell = @"MeInterestCell";
    
    MeInterestCell *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
    if (cell == nil) {
        cell = [[MeInterestCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
    }
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
//    cell.model = self.model;
//    cell.indexPath = indexPath;
    MyselfFollowListModelSub *modelsub = self.model.list[indexPath.row];
    cell.modelSub = modelsub;
    cell.type = self.type;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MyselfFollowListModelSub *modelsub = self.model.list[indexPath.row];
    
    NSLog(@"");
    Ugc_HomePage_VC_V3 *vc = [[Ugc_HomePage_VC_V3 alloc]init];
    vc.userName = modelsub.nickName;
    if (![kUSER_INFO_MANAGER.userId isEqualToString:modelsub.followUserId]) {
        vc.userId = modelsub.followUserId;

    }else{
        vc.userId = modelsub.userId;
    }
    vc.userAvatar = modelsub.avatar;
    [self.getNav pushViewController:vc animated:YES];
    
    
}
    
@end
//_userId    __NSCFString *    @"ADE02E52875148E79FBBD4BDEBF83598"    0x0000600002b0f240
//_avatar    __NSCFString *    @"/gallery/default/cedf2a9436744da89aaf101be829f7c9.jpg"    0x00006000011a5770
